package Connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

/**
 * Klasa pobiera dane z zadanych kolumn z zadanej tabeli w bazie danych.
 * 
 * @author Katarzyna Tarnowska
 * 
 */
public class GenRetriever {
	public ArrayList<String> get(String col, String table) {

		ArrayList<String> results = new ArrayList<String>();
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			Connection conn = DriverManager.getConnection(
					"jdbc:sqlserver://localhost:1433;databaseName=ABSI",
					"Admin", "Admin");
			// System.out.println("connected");
			Statement statement = conn.createStatement();
			String queryString = "SELECT " + col + " FROM [ABSI].[dbo].["
					+ table + "]";
			ResultSet rs = statement.executeQuery(queryString);

			while (rs.next()) {
				results.add(rs.getString(1));
			}
			rs.close();
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return results;
	}

}

